package org.grow.cooldown;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.mongodb.client.MongoCollection;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@SpringBootApplication
public class CooldownApplication {

    public static void main(String[] args) {
        SpringApplication.run(CooldownApplication.class, args);
    }

    @Autowired
    RedisConnectionFactory redisConnectionFactory;
    @Autowired
    ObjectMapper objectMapper;

    @Bean
    public RedisTemplate<String,Object> redisTemplate(){
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String,Object>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        StringRedisSerializer key = new StringRedisSerializer();
        Jackson2JsonRedisSerializer value = new Jackson2JsonRedisSerializer<>(Object.class);
        redisTemplate.setKeySerializer(key);
        redisTemplate.setValueSerializer(value);
        redisTemplate.setHashKeySerializer(key);
        redisTemplate.setHashValueSerializer(value);
        return redisTemplate;

    }
    @Bean
    public MongoCollection<Document> scoreMongo (MongoTemplate mongoTemplate){
        return mongoTemplate.getCollection("score");
    }



}
